5547 Stream Distributions CSV instead of pregenerating#5523
5547 Stream Distributions CSV instead of pregenerating#5523jparcill wants to merge 5 commits intorubyforgood:mainfrom
Conversation
| include ItemsHelper | ||
|
|
||
| def initialize(distributions:, organization:, filters: []) | ||
| # Currently, the @distributions are already loaded by the controllers that are delegating exporting |
There was a problem hiding this comment.
I'm not sure this is actually accurate. I originally used find_each when trying to export on my localenvironment and the code worked.
indicating that the distributions were not in memory yet
I've since switched to using each instead just so that the spec file runs since the tests expect an array
|
So I don't think this really solves the problem - while it won't technically time out, the user will be stuck waiting for a huge amount of time and will have no idea if it's actually working or not. I'd suggest we either:
|
|
I think a big part of why this is slow is because the current implementation loads all the rows into memory before converting it to a CSV. I can batch the SQL requests if we wanna avoid that. In this PR's state I think 3 seconds for 30k rows is not a long wait. This is in contrast to where 30k rows would just time out in the current world I think in the email method we'd run into email size limits with larger csvs. We'd have to do some S3 solution there. |
Resolves #5477
Description
Stream the exporting of the Distributions CSV instead of generating the CSV before download. This allows download to start immediately and at this point the download can occur as long as the client wants.
Type of change
How Has This Been Tested?
Another test that I did was to simulate a large download with the following code on my local env.
This downloaded a 3.5 MB file over >30 seconds.